package com.haochang.chunkvod.model.hostess;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import org.json.JSONArray;
import org.json.JSONObject;

import com.haochang.base.BaseActivity;
import com.haochang.chunkvod.app.common.intent.IntentKey;
import com.haochang.chunkvod.app.config.ApiConfig;
import com.haochang.chunkvod.app.utils.JsonParseUtils;
import com.haochang.chunkvod.app.utils.TimeUtils;
import com.haochang.chunkvod.tools.thirdparty.network.http.httpenum.HttpCacheEnum;
import com.haochang.chunkvod.tools.thirdparty.network.http.httpenum.HttpMethodEnum;
import com.haochang.chunkvod.tools.thirdparty.network.http.httpenum.HttpRequestLoadingEnum;
import com.haochang.chunkvod.tools.thirdparty.network.http.request.HttpRequestBuilder;
import com.haochang.chunkvod.tools.thirdparty.network.http.request.HttpRequestBuilder.IHttpRequestSucessListener;
import com.haochang.chunkvod.tools.thirdparty.network.http.request.HttpRequestTask;
import com.haochang.chunkvod.view.vod.dialog.ActivityDialogItemInfo;
import com.haochang.chunkvod.view.vod.dialog.BaseDialogItemInfo;
import com.haochang.chunkvod.view.vod.dialog.DialogItemInfo;
import com.haochang.chunkvod.view.vod.popupWindow.SecondMenuInfo;

import android.text.TextUtils;
import android.util.SparseArray;

/**
 * @author Yangjie
 *         className ReserveData
 *         created at  2016/8/24  10:33
 *         咨客 各种数据请求 如：预定信息
 */
public class HostessData
{
	private BaseActivity context;

	public HostessData(BaseActivity context)
	{
		this.context = context;
	}

	public interface ResultResponseList<T>
	{
		void onRequestSuccess(List<T> list);

		void onFail(int errno, String errMsg);
	}

	public interface ResultResponseListAndJSONArray<T>
	{
		void onRequestSuccess(List<T> list, JSONArray array, boolean clear);

		void onFail(int errno, String errMsg);
	}

	/**
	 * 可以返回多个list
	 *
	 * @param <T>
	 */
	public interface ResultResponseMultipleList<T>
	{
		void onRequestSuccess(SparseArray<List<T>> list, boolean clear);

		void onFail(int errno, String errMsg);
	}

	/**
	 * 可以返回多个list,存放在hashmap中
	 */
	public interface ResultResponseHashMap
	{
		void onRequestSuccess(HashMap<String, Object> hashMap, boolean clear);

		void onFail();
	}

	public interface ResultResponse
	{
		void onRequestSuccess();

		void onFail(int errorNo, String errorMsg);
	}

	public interface ResultResponseJSONObject
	{
		void onRequestSuccess(JSONObject jsonObject);

		void onFail(int errorNo, String errorMsg);
	}

	public interface ResultResponseString
	{
		void onRequestSuccess(String string);

		void onFail(int errno, String msg);
	}

	public interface IHostessHomeListener
	{
		void onSuccess(int count, List<HostessInfo> list, List<SecondMenuInfo> orderList);

		void onFail(int errno, String errMsg);
	}

	public interface ConsumeInfoListener
	{
		void onRequestSuccess(ConsumeInfo info);

		void onFail(int errno, String errMsg);
	}

	public interface StatementTimeListener
	{
		void onRequestSuccess(String time, long serverTime);

		void onFail(int errno, String errMsg);
	}

	public interface NotificationListener
	{
		void onRequestSuccess(long serverTime, ArrayList<HostessInfo> callRemindInfos, ArrayList<HostessInfo> statementRemindInfos,
				ArrayList<HostessInfo> overRemindInfos);

		void onFail(int errno, String errMsg);
	}

	public interface HostessRoomInfoListener
	{
		void onRequestSuccess(ArrayList<DialogItemInfo> usageList, ArrayList<ActivityDialogItemInfo> activityList, String expectedTime,
				ArrayList<DialogItemInfo> roomPolicies, ArrayList<DialogItemInfo> roomTypes1, String relateCode, String customer_count);

		void onFail(int errorNo, String msg);
	}

	public interface NoticeListener
	{
		void onRequestSuccess(String notice);

		void onFail(int errno, String errMsg);
	}

	public interface DeskListListener
	{
		void onRequestSuccess(ArrayList<HostessInfo> list);

		void onFinish();
	}

	public interface OpenDeskListener
	{
		void onRequestSuccess(String billId);
	}

	/**
	 * 咨客--一键开房(按房型开房) 一键获取顶部房型，活动，列表信息等
	 *
	 * @param listener 监听器
	 */
	public void requestOneKeyOpenRoomInfo(boolean isLoading, final ResultResponseHashMap listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.ONE_KEY_OPEN_ROOM_LIST).param(null)
				.httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(isLoading ? HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT : HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessWithSerTimeListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject, final long serverTime)
					{
						if (jsonObject != null)
						{
							HashMap<String, Object> hashMap = paraseOneKeyOpenRoomInfo(jsonObject, serverTime);
							if (listener != null)
							{
								listener.onRequestSuccess(hashMap, true);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail();
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 请求按房型开房 即一键开房
	 *
	 * @param listener 监听器
	 */
	public void requestOneKeyOpenRoom(HashMap<String, String> map, boolean isLoading, final ResultResponse listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.ONE_KEY_OPEN_ROOM).param(map)
				.httpMethodEnum(HttpMethodEnum.POST).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(isLoading ? HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT : HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							//							List<RoomInfo> list = paraseReserveRoomJson(jsonObject);
							if (listener != null)
							{
								listener.onRequestSuccess();
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 预一键开房预结时间 请求
	 *
	 * @param listener 监听器
	 */
	@SuppressWarnings("unchecked")
	public void requestOneKeyOpenRoomEndTime(boolean isLoading, String room_type_id, final ResultResponseList listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_type_id", room_type_id);
		//		map.put("bill_id","");
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_STATEMENT_TIME).param(map)
				.httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(isLoading ? HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT : HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								List<HostessInfo> list = new ArrayList<HostessInfo>();
								HostessInfo info = new HostessInfo();
								JSONArray array = jsonObject.optJSONArray("bussiness_time_range");
								if (array != null && array.length() >= 2)
								{
									String s = array.optString(1);
									info.setEnd_time(TextUtils.isEmpty(s) ? "" : s);
									list.add(info);
								}
								listener.onRequestSuccess(list);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 预定信息list 请求
	 *
	 * @param listener 监听器
	 */
	@SuppressWarnings("unchecked")
	public void requestReserveRoomStatusList(boolean isLoading, final ResultResponseList listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.RESERVE_ROOM_LIST).param(null)
				.httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(isLoading ? HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT : HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							List<HostessInfo> list = paraseReserveRoomJson(jsonObject);
							if (listener != null)
							{
								listener.onRequestSuccess(list);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取可用房间的list
	 *
	 * @param listener 监听器
	 */
	@SuppressWarnings("unchecked")
	public void requestUsableRoomList(boolean isLoading, final ResultResponseMultipleList listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.USABLE_ROOM_LIST).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).param(null)
				.httpRequestLoadingEnum(isLoading ? HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT : HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							SparseArray<List<HostessInfo>> list = paraseUsableRoomListJson(jsonObject);
							if (listener != null)
							{
								listener.onRequestSuccess(list, true);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取开房排序 区域list
	 *
	 * @param listener 监听器
	 */
	@SuppressWarnings("unchecked")
	public void requestSortRoomAreaList(boolean isLoading, final ResultResponseListAndJSONArray listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.SORT_ROOM_AREA_LIST).param(null)
				.httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(isLoading ? HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT : HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							List<HostessInfo> list = paraseSortRoomAreaJson(jsonObject);
							JSONArray array = getJSONArray(jsonObject);
							if (listener != null)
							{
								listener.onRequestSuccess(list, array, true);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 开房顺序保存
	 *
	 * @param array    组装的array
	 * @param listener 监听器
	 */
	@SuppressWarnings("unchecked")
	public void requestSortRoomSave(JSONArray array, boolean isLoading, final ResultResponse listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("roomweight", array.toString());
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.SORT_ROOM_SAVE).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(isLoading ? HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT : HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess();
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 解析 咨客 一键开房时 各种列表
	 */
	private HashMap<String, Object> paraseOneKeyOpenRoomInfo(JSONObject jsonObject, long serverTime)
	{
		HashMap<String, Object> hashMap = new HashMap<String, Object>();
		JSONArray jsonArrayRoomType = JsonParseUtils.optJSONArray(jsonObject, "room_type_info");//顶部房间选择
		JSONObject jsonObjectActive = JsonParseUtils.optJSONObject(jsonObject, "actives");//活动选择
		JSONObject jsonObjectUsages = JsonParseUtils.optJSONObject(jsonObject, "usages");//房间用途
		JSONArray jsonArrayChargePolicy = JsonParseUtils.optJSONArray(jsonObject, "charging_policies");//计费策略
		ArrayList<DialogItemInfo> listChooseRoomType = new ArrayList<DialogItemInfo>();
		ArrayList<DialogItemInfo> listRoomType = new ArrayList<DialogItemInfo>();
		ArrayList<DialogItemInfo> listFees = new ArrayList<DialogItemInfo>();
		hashMap.put(IntentKey.SERVER_TIME, serverTime);

		if (null != jsonArrayChargePolicy)
		{
			int length = jsonArrayChargePolicy.length();
			listFees.clear();
			for (int i = 0; i < length; i++)
			{
				listFees.add(new DialogItemInfo(i + "", jsonArrayChargePolicy.optString(i), (i == 0)));
			}
		}
		hashMap.put(IntentKey.FEE_TYPE_LIST, listFees);

		if (jsonObjectUsages != null)
		{
			List<String> list = new ArrayList<String>();
			List<String> listCode = new ArrayList<String>();
			JSONArray keys = jsonObjectUsages.names();
			if (keys != null && keys.length() > 0)
			{
				int len = keys.length();
				for (int i = 0; i < len; i++)
				{

					String a = keys.optString(i);
					list.add(jsonObjectUsages.optString(a));
					listCode.add(a);
				}
				hashMap.put(IntentKey.ROOM_USAGE, list);
				hashMap.put(IntentKey.ROOM_USAGE_CODE, listCode);
			}
		}
		if (jsonArrayRoomType != null && jsonArrayRoomType.length() > 0)
		{
			int lenthRoomType = jsonArrayRoomType.length();
			for (int k = 0; k < lenthRoomType; k++)
			{
				JSONObject jObject = jsonArrayRoomType.optJSONObject(k);
				if (jObject == null)
					continue;
				DialogItemInfo info = new DialogItemInfo();
				if (Integer.MAX_VALUE == JsonParseUtils.optInt(jObject, "room_count"))
				{
					continue;
				} else
				{
					info.setRoomNum(jObject.optString("room_count"));
				}
				info.setCode("" + k);
				info.setId(JsonParseUtils.optString(jObject, "room_type_id"));
				info.setTitle(JsonParseUtils.optString(jObject, "room_type_name"));
				info.setName(JsonParseUtils.optString(jObject, "room_type_name") + " ( " + info.getRoomNum() + " )");
				info.setEndTime(jObject.optString("expected_time"));
				info.setNumber(jObject.optString("room_type_default_people"));
				listChooseRoomType.add(info);
				DialogItemInfo info2 = new DialogItemInfo();
				if (k == 0)
				{
					info2.setSelected(true);
				}
				info2.setCode("" + k);
				info2.setId(JsonParseUtils.optString(jObject, "room_type_id"));
				info2.setTitle(JsonParseUtils.optString(jObject, "room_type_name"));
				info2.setName(JsonParseUtils.optString(jObject, "room_type_name"));
				info2.setEndTime(jObject.optString("expected_time"));
				info2.setNumber(jObject.optString("room_type_default_people"));
				listRoomType.add(info2);
			}
			hashMap.put(IntentKey.ROOM_TYPE_CHOOSE_LIST, listChooseRoomType);
			hashMap.put(IntentKey.ROOM_TYPE_LIST, listRoomType);
		}
		if (jsonObjectActive != null)
		{
			hashMap.put(IntentKey.JSONObject, jsonObjectActive);
		}
		return hashMap;
	}

	/**
	 * 解析 可用房间列表
	 */
	private SparseArray<List<HostessInfo>> paraseUsableRoomListJson(JSONObject jsonObject)
	{
		SparseArray<List<HostessInfo>> array = new SparseArray<List<HostessInfo>>();
		JSONArray jsonArrayList = jsonObject.optJSONArray("list");
		if (jsonArrayList != null && jsonArrayList.length() > 0)
		{
			JSONArray jsonArrayTemp = jsonArrayList.optJSONObject(0).optJSONArray("info");
			int lenthColumn = jsonArrayList.length();//列
			int lenthRow = jsonArrayTemp != null ? jsonArrayTemp.length() : 0;//行
			for (int k = 0; k < lenthRow; k++)
			{
				//行
				ArrayList<HostessInfo> list = new ArrayList<HostessInfo>();
				for (int i = 0; i < lenthColumn; i++)
				{
					//列
					JSONObject jObject = jsonArrayList.optJSONObject(i);//整列垂直 包含info的JSONObject
					if (jObject == null)
						continue;
					JSONArray jsonArray2 = jObject.optJSONArray("info");//整列 垂直info
					HostessInfo info = new HostessInfo();
					info.setRoomId(jObject.optString("room_type_id"));
					info.setContent(jObject.optString("room_type_name"));

					if (jsonArray2 != null && jsonArray2.length() > 0)
					{
						JSONObject jsonObject1 = jsonArray2.optJSONObject(k);//对应行列对应的info内部的JSONObject
						if (null != jsonObject1)
						{
							//每一行都设置时间轴
							SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
							SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
							try
							{
								info.setTimeZoom(simpleDateFormat.format(simpleDateFormat1.parse(jsonObject1.optString("time"))));
							} catch (Exception e)
							{
								info.setTimeZoom("time");
							}
							info.setUsableNum(jsonObject1.optString("total_count"));//通过内层获取数量
							info.setReserveNum(jsonObject1.optString("count"));
						}
						list.add(info);
					}
				}
				array.put(k, list);
			}
		}

		return array;
	}

	/**
	 * 解析 开房顺序 区域列表
	 */
	private List<HostessInfo> paraseSortRoomAreaJson(JSONObject jsonObject)
	{
		ArrayList<HostessInfo> list = new ArrayList<HostessInfo>();
		JSONArray jsonArray = JsonParseUtils.optJSONArray(jsonObject, "data");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				JSONObject jObject = jsonArray.optJSONObject(i);
				if (jObject == null)
					continue;
				HostessInfo info = new HostessInfo();
				info.setAreaId(jObject.optString("area_id"));
				info.setContent(jObject.optString("area_name"));
				list.add(info);
			}
		}
		return list;
	}

	/**
	 * 解析 开房顺序 区域列表 获取jsonarray
	 */
	private JSONArray getJSONArray(JSONObject jsonObject)
	{
		return JsonParseUtils.optJSONArray(jsonObject, "data");
	}

	/**
	 * 解析 咨客 预定信息列表
	 */
	private List<HostessInfo> paraseReserveRoomJson(JSONObject jsonObject)
	{
		ArrayList<HostessInfo> reverseRoomInfoArrayList = new ArrayList<HostessInfo>();
		JSONArray jsonArray = JsonParseUtils.optJSONArray(jsonObject, "list");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				JSONObject jObject = jsonArray.optJSONObject(i);
				if (jObject == null)
					continue;
				HostessInfo info = new HostessInfo();
				info.setStart_time(JsonParseUtils.optString(jObject, "time"));
				info.setReserveNum(JsonParseUtils.optString(jObject, "count"));

				reverseRoomInfoArrayList.add(info);
			}
		}
		return reverseRoomInfoArrayList;
	}

	/**
	 * 咨客主页房间或者桌台列表查询
	 *
	 * @param isRoom    是否是房间
	 * @param areaIds   区域编号
	 * @param isLoading 是否重新加载
	 * @param sortType  排序方式
	 * @param listener  访问监听
	 */
	public void requestHomepageRoomOrDeskList(final boolean isRoom, String areaIds, boolean isLoading, String sortType, final IHostessHomeListener listener)
	{
		JSONArray jsonArray = new JSONArray();
		if (!TextUtils.isEmpty(areaIds))
		{
			String[] area_ids = areaIds.split(",");
			for (String str : area_ids)
			{
				if (!TextUtils.isEmpty(str))
					jsonArray.put(str);
			}

		}
		HashMap<String, String> map = new HashMap<String, String>();
		//添加参数
		map.put("area_ids", jsonArray.toString());
		map.put("sort_type", sortType);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(isRoom ? ApiConfig.HOSTESS_HOME_LIST : ApiConfig.GET_DESK_LIST)
				.param(map).httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(isLoading ? HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT : HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								if (isRoom)
								{
									int notifyCount = JsonParseUtils.optInt(jsonObject, "notify_count");
									List<HostessInfo> list = paraseRoomJson(jsonObject);
									List<SecondMenuInfo> listSecondMenu = paraseOrderJson(jsonObject);
									listener.onSuccess(notifyCount, list, listSecondMenu);
								} else
								{
									ArrayList<HostessInfo> list = getDeskList(jsonObject);
									listener.onSuccess(0, list, null);
								}
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 解析排序信息
	 */
	private List<SecondMenuInfo> paraseOrderJson(JSONObject jsonObject)
	{
		ArrayList<SecondMenuInfo> orderList = new ArrayList<SecondMenuInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("sort_types");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			int lenth = jsonArray.length();
			for (int i = 0; i < lenth; i++)
			{
				JSONObject jObject = jsonArray.optJSONObject(i);
				if (jObject == null)
				{
					continue;
				}
				SecondMenuInfo info = new SecondMenuInfo();
				//				int index = JsonParseUtils.optInt(jObject, "id");
				//				if (index != Integer.MAX_VALUE && index >= 0)
				//				{
				//					info.setCode(index + "");
				//				} else
				//				{
				//					info.setCode(jObject.optInt("id") + "");
				//				}
				info.setCode(String.valueOf(i));
				info.setSelected(false);
				info.setName(TextUtils.isEmpty(jObject.optString("title")) ? "" : jObject.optString("title"));
				orderList.add(info);
			}
		}
		return orderList;
	}

	/**
	 * 解析房间信息
	 */
	private List<HostessInfo> paraseRoomJson(JSONObject jsonObject)
	{
		ArrayList<HostessInfo> roomInfoList = new ArrayList<HostessInfo>();
		JSONArray jsonArray = JsonParseUtils.optJSONArray(jsonObject, "rooms_info");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			int count = jsonArray.length();
			for (int i = 0; i < count; i++)
			{
				JSONObject jObject = jsonArray.optJSONObject(i);
				if (jObject == null)
					continue;
				HostessInfo info = new HostessInfo();
				info.setRoomId(jObject.optString("room_id"));
				info.setAreaId(jObject.optString("area_id"));
				info.setAreaName(jObject.optString("area_name"));
				info.setRoomNum(jObject.optString("room_code"));
				info.setRoomTypeId(jObject.optString("room_type_id"));
				info.setRoomType(jObject.optString("room_type_name"));
				info.setCustomerCount(jObject.optInt("customer_count"));
				info.setRoomStatus(jObject.optString("room_status"));
				info.setBillId(jObject.optString("bill_id"));
				info.setBillStatus(jObject.optString("bill_status"));
				info.setUsage(jObject.optString("usage"));
				info.setIsHonor(jObject.optInt("is_honor"));
				info.setRoomWeight(jObject.optInt("room_weight"));
				info.setUnLeave(jObject.optInt("is_unleave"));
				info.setStart_time(jObject.optString("bill_begin_time"));
				info.setEnd_time(jObject.optString("bill_end_time"));
				info.setRemarks(jObject.optString("remarks"));
				info.setClassifyType(0);//桌台标示设置为0
				roomInfoList.add(info);
			}
		}
		return roomInfoList;
	}

	/**
	 * 开机
	 *
	 * @param roomId 房号
	 */
	public void requestOpenRoom(String roomId, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_id", roomId);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTEES_OPEN_ROOM).param(map).httpMethodEnum(HttpMethodEnum.PUT).param(map)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess("success");
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 取消带客
	 *
	 * @param roomId 房号
	 */
	public void requestCancelGuilding(String roomId, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_id", roomId);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_CANCEL_GUILDING).param(map).httpMethodEnum(HttpMethodEnum.DELETE).param(map)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess("success");
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 设置为空房(管理员)
	 *
	 * @param roomId 房号
	 */
	public void setRoomToEmptyManager(String roomId, String token, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_id", roomId);
		map.put("auth_code", token);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTEES_TO_EMPTY_MANAGE).param(map).httpMethodEnum(HttpMethodEnum.PUT).param(map)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess("success");
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 设置为空房
	 *
	 * @param roomId 房号
	 */
	public void setRoomToEmpty(String roomId, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_id", roomId);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTEES_TO_EMPTY).param(map).httpMethodEnum(HttpMethodEnum.PUT).param(map)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess("success");
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 设置为清洁（管理员）
	 *
	 * @param roomId 房号
	 */
	public void setRoomToClearManager(String roomId, String token, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_id", roomId);
		map.put("auth_code", token);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_TO_CLEAR_MANAGE).param(map).httpMethodEnum(HttpMethodEnum.PUT).param(map)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess("success");
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 设置为清洁
	 *
	 * @param roomId 房号
	 */
	public void setRoomToClear(String roomId, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_id", roomId);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_TO_CLEAR).param(map).httpMethodEnum(HttpMethodEnum.PUT).param(map)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess("success");
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 设置未维修
	 *
	 * @param roomId 房号
	 */
	public void setRoomToRepair(String roomId, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_id", roomId);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_TO_REPAIR).param(map).httpMethodEnum(HttpMethodEnum.PUT).param(map)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess("success");
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 获取消费列表数据
	 */
	@SuppressWarnings("unchecked")
	public void requestConsumeList(final ResultResponseList listListener)
	{
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_CONSUME_LIST).param(null).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							List<ConsumeQueryInfo> list = paraseConsumeJson(jsonObject);
							if (listListener != null)
							{
								listListener.onRequestSuccess(list);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listListener)
						{
							listListener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 解析消费列表信息
	 */
	private List<ConsumeQueryInfo> paraseConsumeJson(JSONObject jsonObject)
	{
		ArrayList<ConsumeQueryInfo> roomInfoList = new ArrayList<ConsumeQueryInfo>();
		JSONArray jsonArray = JsonParseUtils.optJSONArray(jsonObject, "list");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				JSONObject jObject = jsonArray.optJSONObject(i);
				if (jObject == null)
					continue;
				ConsumeQueryInfo info = new ConsumeQueryInfo();
				info.setRoomId(jObject.optString("room_id"));
				info.setAreaId(jObject.optString("area_id"));
				info.setAreaName(jObject.optString("area_name"));
				info.setRoomNum(jObject.optString("room_code"));
				info.setRoomTypeId(jObject.optString("room_type_id"));
				info.setRoomTypeName(jObject.optString("room_type_name"));
				info.setCustomerCount(
						Integer.MAX_VALUE == JsonParseUtils.optInt(jObject, "customer_count") ? 0 : JsonParseUtils.optInt(jObject, "customer_count"));
				info.setRoomStatus(jObject.optString("room_status"));
				info.setBillId(jObject.optString("bill_id"));
				info.setBillStatus(jObject.optString("bill_status"));
				info.setUsage(jObject.optString("usage"));
				info.setIsHonor(Integer.MAX_VALUE == JsonParseUtils.optInt(jObject, "is_honor") ? 0 : JsonParseUtils.optInt(jObject, "is_honor"));
				info.setRoomWeight(Integer.MAX_VALUE == JsonParseUtils.optInt(jObject, "room_weight") ? 0 : JsonParseUtils.optInt(jObject, "room_weight"));
				info.setBeginTime(jObject.optString("begin_time"));
				info.setEndTime(jObject.optString("end_time"));
				int consume = JsonParseUtils.optInt(jObject, "consume");
				info.setConsume(Integer.MAX_VALUE == consume ? 0 : consume);
				info.setDefaultCustomerCount(Integer.MAX_VALUE == JsonParseUtils.optInt(jObject, "default_customer_count") ? 0
						: JsonParseUtils.optInt(jObject, "default_customer_count"));
				info.setConsumeTime(TimeUtils.timeBetween(jObject.optString("end_time"), jObject.optString("begin_time")));
				int customer_count = JsonParseUtils.optInt(jObject, "customer_count");
				if (Integer.MAX_VALUE != customer_count && customer_count > 0)
				{
					info.setConsumeAvg(consume / customer_count);
				} else
				{
					info.setConsumeAvg(0);
				}
				roomInfoList.add(info);
			}
		}
		return roomInfoList;
	}

	/**
	 * 刷新一键开房 的活动
	 *
	 * @param activeId 活动id
	 */
	public ArrayList<ActivityDialogItemInfo> refreshActivity(JSONObject jsonObjectActive, String activeId)
	{
		ArrayList<ActivityDialogItemInfo> listChooseActivity = new ArrayList<ActivityDialogItemInfo>();//活动
		if (!TextUtils.isEmpty(activeId) && null != jsonObjectActive)
		{
			JSONArray jsonArray = JsonParseUtils.optJSONArray(jsonObjectActive, activeId);
			if (null != jsonArray && jsonArray.length() > 0)
			{
				ActivityDialogItemInfo infoNoChoose = new ActivityDialogItemInfo("0", "不选择活动", true);
				infoNoChoose.setId("");
				listChooseActivity.add(infoNoChoose);
				int len = jsonArray.length();
				for (int i = 0; i < len; i++)
				{
					JSONObject jsonObject = jsonArray.optJSONObject(i);
					if (null != jsonObject)
					{
						ActivityDialogItemInfo info = new ActivityDialogItemInfo();
						info.setName(JsonParseUtils.optString(jsonObject, "name"));
						int price = JsonParseUtils.optInt(jsonObject, "sale_price");
						if (Integer.MAX_VALUE != price)
						{
							info.setContent("¥" + price / 100);
							info.setNumber(price / 100 + "");
						}
						info.setUnit(JsonParseUtils.optString(jsonObject, "unit"));
						info.setId(JsonParseUtils.optString(jsonObject, "active_id"));
						JSONArray jsonArrayGoodList = jsonObject.optJSONArray("goods_list");
						List<BaseDialogItemInfo> listGoodDetail = new ArrayList<BaseDialogItemInfo>();
						//添加减免分钟项
						if (!TextUtils.isEmpty(JsonParseUtils.optString(jsonObject, "decrease_time")))
						{
							BaseDialogItemInfo info1 = new BaseDialogItemInfo();
							info1.setName("减免" + JsonParseUtils.optString(jsonObject, "decrease_time") + "分钟房费");
							info1.setContent("");
							listGoodDetail.add(info1);
						}
						if (jsonArrayGoodList != null && jsonArrayGoodList.length() > 0)
						{
							int length = jsonArrayGoodList.length();
							for (int j = 0; j < length; j++)
							{
								//商品list
								JSONObject jsonObjectGoodDetail = jsonArrayGoodList.optJSONObject(j);//商品详情
								if (null != jsonObjectGoodDetail)
								{
									BaseDialogItemInfo info1 = new BaseDialogItemInfo();
									info1.setName(JsonParseUtils.optString(jsonObjectGoodDetail, "cn_name"));
									info1.setContent(JsonParseUtils.optString(jsonObjectGoodDetail, "quantity")
											+ JsonParseUtils.optString(jsonObjectGoodDetail, "unit"));
									info1.setUnit(JsonParseUtils.optString(jsonObjectGoodDetail, "unit"));
									info1.setNumber(JsonParseUtils.optString(jsonObjectGoodDetail, "quantity"));
									listGoodDetail.add(info1);
								}
							}
						}
						info.setList(listGoodDetail);
						listChooseActivity.add(info);
					}
				}
			}
		}
		return listChooseActivity;
	}

	/**
	 * 获取消费详情
	 */
	public void requestConsumeInfo(String billId, final ConsumeInfoListener listListener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_CONSUME_INFO).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							ConsumeInfo info = new ConsumeInfo();
							try
							{
								JSONObject jObj = jsonObject.optJSONObject("detail");
								info.setConsume(jObj.optInt("consume"));
								info.setCustomer_count(jObj.optInt("customer_count"));
								info.setRoom_fee(jObj.optInt("room_fee"));
								info.setBegin_time(jObj.optString("begin_time"));
								info.setEnd_time(jObj.optString("end_time"));
								JSONArray obj = jObj.optJSONArray("goods_list_fee");
								ArrayList<GoodsFeeInfo> list = paraseConsumeInfoJson(obj);
								info.setGoodsFeeInfos(list);
							} catch (Exception e)
							{
								e.printStackTrace();
							}
							if (listListener != null)
							{
								listListener.onRequestSuccess(info);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listListener)
						{
							listListener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 解析消费商品列表
	 */
	private ArrayList<GoodsFeeInfo> paraseConsumeInfoJson(JSONArray obj)
	{
		ArrayList<GoodsFeeInfo> infos = new ArrayList<GoodsFeeInfo>();
		if (obj != null)
		{
			for (int i = 0; i < obj.length(); i++)
			{
				JSONObject o = obj.optJSONObject(i);
				if (Integer.parseInt(o.optString("num")) > 0)
				{
					GoodsFeeInfo info = new GoodsFeeInfo();
					info.setCount(o.optInt("num"));
					info.setGoodsName(o.optString("cn_name"));
					info.setIs_give(o.optInt("is_present") > 0);
					info.setMoney(o.optInt("sale_price"));
					infos.add(info);
				}
			}
		}
		return infos;
	}

	/**
	 * 权限验证
	 */
	public void requestAuthorization(String interfaceName, String name, String pwd, String eventId, final ResultResponseString listListener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("staff_number", name);
		map.put("password", pwd);
		if (!TextUtils.isEmpty(eventId))
			map.put("event", eventId);
		new HttpRequestBuilder(context).interfaceName(interfaceName).param(map).httpMethodEnum(HttpMethodEnum.POST).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT).httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							String token = jsonObject.optString("auth_code");
							if (listListener != null)
							{
								listListener.onRequestSuccess(token);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listListener)
						{
							listListener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 获取所有空房列表数据
	 */
	@SuppressWarnings("unchecked")
	public void requestEmptyRoomList(final ResultResponseList listListener)
	{
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_EMPTY_ROOM).param(null).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							ArrayList<HostessInfo> list = paraseEmptyRoomJson(jsonObject);
							if (listListener != null)
							{
								listListener.onRequestSuccess(list);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listListener)
						{
							listListener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 解析空房列表数据
	 */
	private ArrayList<HostessInfo> paraseEmptyRoomJson(JSONObject jsonObject)
	{
		ArrayList<HostessInfo> list = new ArrayList<HostessInfo>();
		if (jsonObject != null)
		{
			JSONArray array = jsonObject.optJSONArray("data");
			for (int i = 0; i < array.length(); i++)
			{
				HostessInfo info = new HostessInfo();
				JSONObject jObject = array.optJSONObject(i);
				info.setRoomTypeId(jObject.optString("room_type_id"));
				info.setRoomType(jObject.optString("room_type_name"));
				JSONArray arr = jObject.optJSONArray("rooms");
				ArrayList<HostessInfo> rooms = new ArrayList<HostessInfo>();
				for (int j = 0; j < arr.length(); j++)
				{
					HostessInfo temp = new HostessInfo();
					JSONObject obj = arr.optJSONObject(j);
					temp.setRoomId(obj.optString("id"));
					temp.setRoomNum(obj.optString("code"));
					temp.setRoomTypeId(jObject.optString("room_type_id"));
					rooms.add(temp);
				}
				info.setRooms(rooms);
				list.add(info);
			}
		}
		return list;
	}

	/**
	 * 获取最长预结时间(管理员)
	 *
	 * @param billId 账单号
	 */
	public void requestMostStatementTimeManager(String roomTypeId, String billId, final StatementTimeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_type_id", roomTypeId);
		if (!TextUtils.isEmpty(billId))
		{
			map.put("bill_id", billId);
		}
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_STATEMENT_TIME_MANAGER).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessWithSerTimeListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject, long serverTime)
					{
						if (jsonObject != null)
						{
							String time = jsonObject.optString("expected_time");
							if (listener != null)
								listener.onRequestSuccess(time, serverTime);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
							listener.onFail(errno, errMsg);
					}
				}).build().execute();
	}

	/**
	 * 获取最长预结时间
	 *
	 * @param billId 账单号
	 */
	public void requestMostStatementTime(String roomTypeId, String billId, final StatementTimeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_type_id", roomTypeId);
		if (!TextUtils.isEmpty(billId))
		{
			map.put("bill_id", billId);
		}
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_STATEMENT_TIME).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessWithSerTimeListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject, long serverTime)
					{
						if (jsonObject != null)
						{
							String time = jsonObject.optString("expected_time");
							if (listener != null)
								listener.onRequestSuccess(time, serverTime);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
							listener.onFail(errno, errMsg);
					}
				}).build().execute();
	}

	/**
	 * 获取提醒信息
	 */
	public void requestNotification(final NotificationListener listener)
	{
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_NOTIFICATION).param(null).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessWithSerTimeListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject, long serverTime)
					{
						if (jsonObject != null)
						{
							ArrayList<HostessInfo> listCalling = paraseCallNotification(serverTime, jsonObject);
							ArrayList<HostessInfo> listReservation = paraseStatementNotification(jsonObject);
							ArrayList<HostessInfo> listOvertime = paraseOverNotification(jsonObject);
							if (listener != null)
							{
								listener.onRequestSuccess(serverTime, listCalling, listReservation, listOvertime);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{
					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 解析呼叫提醒
	 */
	private ArrayList<HostessInfo> paraseCallNotification(long serverTime, JSONObject jsonObject)
	{
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
		SimpleDateFormat simpleDateFormatHH = new SimpleDateFormat("HH:mm", Locale.getDefault());
		ArrayList<HostessInfo> list = new ArrayList<HostessInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("service");
		if (jsonArray == null || jsonArray.length() <= 0)
			return list;
		int lenth = jsonArray.length();
		String serverStartTime = null;
		boolean exception = false;
		try
		{
			serverStartTime = simpleDateFormat.format(new Date(serverTime * 1000));
		} catch (Exception e)
		{
			exception = true;
		}

		for (int i = 0; i < lenth; i++)
		{
			JSONObject obj = jsonArray.optJSONObject(i);
			HostessInfo info = new HostessInfo();
			info.setRoomId(obj.optString("room_id"));
			info.setStart_time(simpleDateFormatHH.format(new Date(obj.optInt("start_time") * 1000)));
			info.setRoomNum(obj.optString("room_code"));
			if (exception)
			{//使用本地时间
				info.setTime(String.valueOf(TimeUtils.timeBetween(TimeUtils.getNowTime(), simpleDateFormat.format(new Date(obj.optInt("start_time") * 1000)))));
			} else
			{//使用服务器时间
				info.setTime(String.valueOf(TimeUtils.timeBetween(serverStartTime, simpleDateFormat.format(new Date(obj.optInt("start_time") * 1000)))));
			}
			list.add(info);
		}
		return list;
	}

	/**
	 * 解析预结提醒
	 */
	private ArrayList<HostessInfo> paraseStatementNotification(JSONObject jsonObject)
	{
		ArrayList<HostessInfo> list = new ArrayList<HostessInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("expected");
		if (jsonArray == null || jsonArray.length() <= 0)
		{
			return list;
		}
		int lenth = jsonArray.length();
		for (int i = 0; i < lenth; i++)
		{
			JSONObject obj = jsonArray.optJSONObject(i);
			if (obj == null)
			{
				continue;
			}
			int rest = JsonParseUtils.optInt(obj, "rest");
			if (Integer.MAX_VALUE != rest && Math.abs(rest) > 0)
			{
				HostessInfo info = new HostessInfo();
				info.setRoomId(obj.optString("room_id"));
				info.setRoomNum(obj.optString("room_code"));
				info.setRemainTime(rest / 60 + "");
				info.setStatementTime(TimeUtils.getTimeString(obj.optLong("end_time") * 1000));
				list.add(info);
			}
		}
		return list;
	}

	/**
	 * 转包提交
	 */
	public void postSubRoom(String billId, String currentRoom, String roomTyoeId, String token, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_id", currentRoom);
		map.put("bill_id", billId);
		if (!TextUtils.isEmpty(token))
		{
			map.put("charging_room_type_id", roomTyoeId);
			map.put("auth_code", token);
		}
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_SUB_COMMIT).param(map).httpMethodEnum(HttpMethodEnum.POST)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess("success");
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 获取房间信息
	 */
	public void requestRoomInfo(String roomId, final String roomTypeId, final HostessRoomInfoListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_id", roomId);
		HttpRequestTask task = new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_ROOM_MANAGE).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							ArrayList<DialogItemInfo> usageList = getUsageList(jsonObject);
							ArrayList<ActivityDialogItemInfo> activityList = getActivityList(jsonObject, roomTypeId);
							ArrayList<DialogItemInfo> roomPolicies = getPoliciesList(jsonObject);
							ArrayList<DialogItemInfo> roomTypes = getRoomType(jsonObject);
							String relateCode = jsonObject.optString("relate_code");
							String expectedTime = jsonObject.optString("expected_time");
							JSONObject jsonObject1 = jsonObject.optJSONObject("room_info");
							String customer_count = null;
							if (jsonObject1 != null)
							{
								customer_count = jsonObject1.optString("customer_count");
							}
							if (listener != null)
							{
								listener.onRequestSuccess(usageList, activityList, expectedTime, roomPolicies, roomTypes, relateCode, customer_count);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build();
		task.execute();
	}

	/**
	 * 解析超时提醒
	 */
	private ArrayList<HostessInfo> paraseOverNotification(JSONObject jsonObject)
	{
		ArrayList<HostessInfo> list = new ArrayList<HostessInfo>();
		JSONArray array = jsonObject.optJSONArray("timeout");
		if (array == null || array.length() <= 0)
		{
			return list;
		}
		int length = array.length();
		for (int i = 0; i < length; i++)
		{
			JSONObject obj = array.optJSONObject(i);
			HostessInfo info = new HostessInfo();
			info.setRoomNum(obj.optString("room_code"));
			info.setOverType(obj.optString("status_label"));
			int timeout = JsonParseUtils.optInt(obj, "timeout");
			info.setOverTime((Integer.MAX_VALUE == timeout) ? 0 + "" : timeout / 60 + "");
			list.add(info);
		}
		return list;
	}

	/**
	 * 解析计费房型
	 */
	private ArrayList<DialogItemInfo> getRoomType(JSONObject jsonObject)
	{
		ArrayList<DialogItemInfo> list = new ArrayList<DialogItemInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("charging_room_types");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				DialogItemInfo info = new DialogItemInfo();
				JSONObject obj = jsonArray.optJSONObject(i);
				info.setCode(obj.optString("room_type_id"));
				info.setName(obj.optString("name"));
				info.setSelected(false);
				list.add(info);
			}
		}
		return list;
	}

	/**
	 * 解析计费策略列表
	 */
	private ArrayList<DialogItemInfo> getPoliciesList(JSONObject jsonObject)
	{
		ArrayList<DialogItemInfo> list = new ArrayList<DialogItemInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("charging_policies");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			int length = jsonArray.length();
			for (int i = 0; i < length; i++)
			{
				DialogItemInfo info = new DialogItemInfo();
				info.setCode(i + "");
				info.setName(jsonArray.optString(i));
				info.setSelected(false);
				list.add(info);
			}
		}
		return list;
	}

	/**
	 * 解析用途列表
	 */
	private ArrayList<DialogItemInfo> getUsageList(JSONObject jsonObject)
	{
		ArrayList<DialogItemInfo> list = new ArrayList<DialogItemInfo>();
		JSONObject jsonObjectUsages = jsonObject.optJSONObject("usages");//房间用途
		if (jsonObjectUsages != null)
		{
			JSONArray keys = jsonObjectUsages.names();
			if (keys != null && keys.length() > 0)
			{
				int len = keys.length();
				for (int i = 0; i < len; i++)
				{
					String a = keys.optString(i);
					DialogItemInfo info = new DialogItemInfo();
					info.setName(jsonObjectUsages.optString(a));
					info.setCode(a);
					info.setSelected(false);
					list.add(info);
				}
			}
		}
		return list;
	}

	/**
	 * 解析活动列表
	 */
	public ArrayList<ActivityDialogItemInfo> getActivityList(JSONObject jsonObject1, String roomTypeId)
	{
		ArrayList<ActivityDialogItemInfo> listChooseActivity = new ArrayList<ActivityDialogItemInfo>();
		JSONObject jsonArray1 = jsonObject1.optJSONObject("actives");
		JSONArray jsonArray = jsonArray1.optJSONArray(roomTypeId);
		if (null != jsonArray && jsonArray.length() > 0)
		{
			ActivityDialogItemInfo infoNoChoose = new ActivityDialogItemInfo("0", "不选择活动", true);
			infoNoChoose.setId("");
			listChooseActivity.add(infoNoChoose);
			int len = jsonArray.length();
			for (int i = 0; i < len; i++)
			{
				JSONObject jsonObject = jsonArray.optJSONObject(i);
				if (null != jsonObject)
				{
					ActivityDialogItemInfo info = new ActivityDialogItemInfo();
					info.setName(JsonParseUtils.optString(jsonObject, "name"));
					int price = JsonParseUtils.optInt(jsonObject, "sale_price");
					if (Integer.MAX_VALUE != price)
					{
						info.setContent("¥" + price / 100);
						info.setNumber(price / 100 + "");
					}
					info.setUnit(JsonParseUtils.optString(jsonObject, "unit"));
					info.setId(JsonParseUtils.optString(jsonObject, "active_id"));
					JSONArray jsonArrayGoodList = jsonObject.optJSONArray("goods_list");
					List<BaseDialogItemInfo> listGoodDetail = new ArrayList<BaseDialogItemInfo>();
					//添加减免分钟项
					if (!TextUtils.isEmpty(JsonParseUtils.optString(jsonObject, "decrease_time")))
					{
						BaseDialogItemInfo info1 = new BaseDialogItemInfo();
						info1.setName("减免" + JsonParseUtils.optString(jsonObject, "decrease_time") + "分钟房费");
						info1.setContent("");
						listGoodDetail.add(info1);
					}
					if (jsonArrayGoodList != null && jsonArrayGoodList.length() > 0)
					{
						int length = jsonArrayGoodList.length();
						for (int j = 0; j < length; j++)
						{
							//商品list
							JSONObject jsonObjectGoodDetail = jsonArrayGoodList.optJSONObject(j);//商品详情
							if (null != jsonObjectGoodDetail)
							{
								BaseDialogItemInfo info1 = new BaseDialogItemInfo();
								info1.setName(JsonParseUtils.optString(jsonObjectGoodDetail, "cn_name"));
								info1.setContent(
										JsonParseUtils.optString(jsonObjectGoodDetail, "quantity") + JsonParseUtils.optString(jsonObjectGoodDetail, "unit"));
								info1.setUnit(JsonParseUtils.optString(jsonObjectGoodDetail, "unit"));
								info1.setNumber(JsonParseUtils.optString(jsonObjectGoodDetail, "quantity"));
								listGoodDetail.add(info1);
							}
						}
					}
					info.setList(listGoodDetail);
					listChooseActivity.add(info);
				}
			}
		}
		return listChooseActivity;
	}

	/**
	 * 生成订单
	 */
	public void requestCreateBill(String roomId, String costomerCount, String activeId, String usage, String roomPolicy, String expTime, String roomType,
			String remarks, int isHonor, String token, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("room_id", roomId);
		map.put("customer_count", costomerCount);
		map.put("active_id", activeId);
		map.put("usage", usage);
		map.put("remarks", remarks);
		map.put("is_honor", isHonor + "");
		if (!TextUtils.isEmpty(token))
		{
			map.put("charging_policy", roomPolicy);
			map.put("charging_room_type_id", roomType);
			map.put("auth_code", token);
			map.put("expected_time", expTime);
		}
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_CREATE_BILL).param(map).httpMethodEnum(HttpMethodEnum.POST)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess("success");
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 修改订单
	 */
	public void requestUpdateBill(String billId, String customerCount, String remarks, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		map.put("customer_count", customerCount);
		map.put("remarks", remarks);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_CREATE_BILL).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess("success");
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 重新获取房间码
	 */
	public void requestRoomCode(String billId, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.HOSTESS_ROOM_CODE).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							String code = jsonObject.optString("relate_code");
							if (listener != null)
							{
								listener.onRequestSuccess(code);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 修改预结时间
	 */
	public void requestUpdateExpTime(String billId, String roomTypeId, String expTime, String roomCode, String token, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		map.put("room_type_id", roomTypeId);
		map.put("expected_time", expTime);
		map.put("relate_code", roomCode);
		if (!TextUtils.isEmpty(token))
		{
			map.put("auth_code", token);
		}
		new HttpRequestBuilder(context).interfaceName(ApiConfig.UPDATE_EXP_TIME).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess("success");
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 获取桌台列表
	 */
	public void requestDeskList(String areaIds, boolean isLoading, final DeskListListener listener)
	{
		JSONArray jsonArray = new JSONArray();
		if (!TextUtils.isEmpty(areaIds))
		{
			String[] area_ids = areaIds.split(",");
			for (String str : area_ids)
			{
				if (!TextUtils.isEmpty(str))
					jsonArray.put(str);
			}
		}
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("area_ids", jsonArray.toString());
		new HttpRequestBuilder(context).interfaceName(ApiConfig.GET_DESK_LIST).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestLoadingEnum(isLoading ? HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT : HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							ArrayList<HostessInfo> list = getDeskList(jsonObject);
							if (listener != null)
							{
								listener.onRequestSuccess(list);
								listener.onFinish();
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFinish();
						}
					}
				}).build().execute();
	}

	/**
	 * 解析桌台列表
	 */
	private ArrayList<HostessInfo> getDeskList(JSONObject jsonObject)
	{
		ArrayList<HostessInfo> list = new ArrayList<HostessInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("lists");
		if (jsonArray != null)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				HostessInfo info = new HostessInfo();
				JSONObject obj = jsonArray.optJSONObject(i);
				info.setRoomId(obj.optString("desk_id"));
				info.setRoomNum(obj.optString("desk_code"));
				info.setAbsNumber(obj.optInt("abs_number"));
				info.setRoomTypeId(obj.optString("desk_type_id"));
				info.setRoomStatus(obj.optString("desk_status"));
				info.setStart_time(obj.optString("bill_begin_time"));
				info.setEnd_time(obj.optString("bill_end_time"));
				info.setRemarks(obj.optString("remarks"));
				info.setBillId(obj.optString("bill_id"));
				info.setCustomerCount(obj.optInt("customer_count"));
				info.setClassifyType(1);//桌台标示设置为1
				list.add(info);
			}
		}
		return list;
	}

	/**
	 * 开台
	 */
	public void requestOpenDesk(String deskId, String customerCount, String remarks, final OpenDeskListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("desk_id", deskId);
		map.put("customer_count", customerCount);
		map.put("remarks", remarks);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.OPEN_DESK).param(map).httpMethodEnum(HttpMethodEnum.POST).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT).httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							String billId = jsonObject.optString("bill_id");
							if (listener != null)
							{
								listener.onRequestSuccess(billId);
							}
						}
					}
				}).build().execute();
	}

	/**
	 * 获取空桌台列表
	 */
	public void requestEmptyDeskList(final DeskListListener listener)
	{
		new HttpRequestBuilder(context).interfaceName(ApiConfig.EMPTY_DESK_LIST).param(null).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							ArrayList<HostessInfo> list = getEmptyDeskList(jsonObject);
							if (listener != null)
							{
								listener.onRequestSuccess(list);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
					}
				}).build().execute();
	}

	/**
	 * 解析空桌台列表
	 */
	private ArrayList<HostessInfo> getEmptyDeskList(JSONObject jsonObject)
	{
		ArrayList<HostessInfo> list = new ArrayList<HostessInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("list");
		if (jsonArray != null)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				JSONObject jObj = jsonArray.optJSONObject(i);
				if (jObj != null)
				{
					HostessInfo info = new HostessInfo();
					info.setRoomType(jObj.optString("desk_type_name"));
					JSONArray arr = jObj.optJSONArray("desks");
					if (arr != null)
					{
						ArrayList<HostessInfo> rooms = new ArrayList<HostessInfo>();
						for (int j = 0; j < arr.length(); j++)
						{
							JSONObject obj = arr.optJSONObject(j);
							HostessInfo temp = new HostessInfo();
							temp.setRoomId(obj.optString("desk_id"));
							temp.setRoomNum(obj.optString("desk_name"));
							rooms.add(temp);
						}
						info.setRooms(rooms);
					}
					list.add(info);
				}
			}
		}
		return list;
	}

	/**
	 * 提交转台
	 */
	public void requestSubDesk(String billId, String deskId, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		map.put("desk_id", deskId);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.SUB_DESK).param(map).httpMethodEnum(HttpMethodEnum.POST).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT).httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess("success");
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 转空台
	 *
	 * @param deskId 桌台号
	 * @param force  是否强制转空
	 */
	public void requestDeskToNone(String deskId, int force, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("force", force + "");
		map.put("desk_id", deskId);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.DESK_TO_NONE).param(map).httpMethodEnum(HttpMethodEnum.POST)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess("success");
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 桌台设置
	 *
	 * @param billId        billid
	 * @param customerCount customerCount
	 * @param remarks       remarks
	 * @param listener      listener
	 */
	public void requestDeskSetting(String billId, String customerCount, String remarks, final NoticeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		map.put("customer_count", customerCount);
		map.put("remarks", remarks);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.DESK_SETTING).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess("success");
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * APP 更新
	 *
	 * @param listener ResultResponseJSONObject
	 */
	public void requestUpdateVersion(final ResultResponseJSONObject listener)
	{
		new HttpRequestBuilder(context).interfaceName(ApiConfig.UPDATE_VERSION).param(null).httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.DISABLE)
				.httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_NONE).isTokenEffective(false)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess(jsonObject);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 预留房间--新增预留房间
	 */
	public void requestAddReserveRoom(String param1, final ResultResponse listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("param1", param1);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.DESK_SETTING).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess();
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 预留房间--预留房间列表
	 */
	@SuppressWarnings("unchecked")
	public void requestReserveRoomList(String param1, final ResultResponseList listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("param1", param1);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.DESK_SETTING).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess(new ArrayList());
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 现场排号--现场排号列表
	 */
	@SuppressWarnings("unchecked")
	public void requestLivaARawNumberList(String param1, final ResultResponseList listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("param1", param1);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.DESK_SETTING).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess(new ArrayList());
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 预付列表
	 */
	@SuppressWarnings("unchecked")
	public void requestAdvancesReceivedList(String param1, final ResultResponseList listener)
	{
		HashMap<String, String> hashMap = new HashMap<String, String>();
		hashMap.put("vava", param1);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.RESERVE_ROOM_LIST).param(hashMap)
				.httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							List<HostessInfo> list = paraseReserveRoomJson(jsonObject);
							if (listener != null)
							{
								listener.onRequestSuccess(list);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 预留房间--房型列表
	 */
	@SuppressWarnings("unchecked")
	public void requestRoomTypeList(String param1, final ResultResponseList listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("param1", param1);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.SUB_DESK).param(map).httpMethodEnum(HttpMethodEnum.PUT).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_NONE).httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess(new ArrayList());
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 咨客--现场排号--新增
	 */
	public void requestAddLiveARowNumber(String roomType, int count, final ResultResponse listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("roomType", roomType);
		map.put("count", String.valueOf(count));
		new HttpRequestBuilder(context).interfaceName(ApiConfig.DESK_SETTING).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess();
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 发送字幕
	 */
	public void requestSendSubtitle(String content, String room, String playCount, String playMode, String canTrigger, final ResultResponse listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("content", content);
		map.put("room", room);
		map.put("playCount", playCount);
		map.put("playMode", playMode);
		map.put("canTrigger", canTrigger);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.DESK_SETTING).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess();
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 预收/代付--添加预收
	 *
	 * @param content              备注
	 * @param advanceReceiveType   预收类型
	 * @param cashAmount           现金金额
	 * @param membershipCardAmount 会员卡金额
	 * @param swippingCardAmount   刷卡金额
	 */
	public void requestAddAdvancesReceived(String content, String advanceReceiveType, String cashAmount, String membershipCardAmount, String swippingCardAmount,
			final ResultResponse listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("content", content);
		map.put("advanceReceiveType", advanceReceiveType);
		map.put("cashAmount", cashAmount);
		map.put("membershipCardAmount", membershipCardAmount);
		map.put("swippingCardAmount", swippingCardAmount);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.DESK_SETTING).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess();
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 预收/代付--添加代付
	 *
	 * @param content  备注
	 * @param amount   金额
	 * @param listener 回调
	 */
	public void requestAddInsteadCharging(String content, String amount, final ResultResponse listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("content", content);
		map.put("amount", amount);
		new HttpRequestBuilder(context).interfaceName(ApiConfig.DESK_SETTING).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{
					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess();
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build().execute();
	}

	/**
	 * 获取ip配置列表
	 */
	@SuppressWarnings("unchecked")
	public void requestIpconfigList(String param1, final ResultResponseList listener)
	{
		HashMap<String, String> hashMap = new HashMap<String, String>();
		hashMap.put("vava", param1);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.IP_CONFIG).param(hashMap).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess(new ArrayList());
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}
}